<?php
namespace app\demo\controller;

use yunj\Controller;
use app\demo\enum\Grade;
use app\demo\service\ImportDemo as Service;

class ImportDemo extends Controller {

    public function index(){
        // 方式一：链式操作
        $builder=YI('demo')
            ->sheets(Grade::texts())
            ->cols(function ($sheet){return Service::instance()->cols($sheet);})
            //->row(function ($sheet,$row_data){return Service::instance()->row($sheet,$row_data);});
            ->rows(function ($rows_data){return Service::instance()->rows($rows_data);});
        // 方式二：数组配置
//        $args = [
//            "sheets"=>Grade::texts(),
//            "cols"=>function ($sheet){
//                return Service::instance()->cols($sheet);
//            },
//            "rows"=>function ($rows_data){
//                return Service::instance()->rows($rows_data);
//            }
//        ];
//        $builder=YI('demo',$args);

        $builder->assign($this);
        return $this->fetch();
    }

}